package handler

import (
	"database/sql"

	"gitee.com/hp-huiw/family-expense-api/internal/service"
	"github.com/gin-gonic/gin"
)

type RegionHandler interface {
	Query(ctx *gin.Context)
}

func NewRegionHandler(db *sql.DB) RegionHandler {
	return &regionHandler{
		regionService: service.NewRegionService(db),
	}
}

// Matches /query-all of http get action.
func (h *regionHandler) Query(ctx *gin.Context) {
	c := ctx.Request.Context()
	result, err := h.regionService.Query(c)

	if err != nil {
		ctx.Error(err)
		return
	}

	SendDataResponse(ctx, result)
}

// Container of RegionHandler functions.
type regionHandler struct {
	regionService service.RegionService
}
